<?php
	session_start();
	/**
	* @package ParkFind
	* @desc This file contains the function to delete or edit profile.
	*/
	//check for direct calling
	if(!isset($_SESSION['user_id']))
	{
		header('Location: index.php');
		exit();
	}
	
	if(!isset($_GET['action']))
		die("Do not call this page directly");	
	
	
	/**
	* @desc This include file will load the directory settings for the Smarty Templates
	*/
	require 'includes/smarty.inc';
	$smarty->assign('user_id', $_SESSION["user_id"]);	
	$smarty->assign('title', "Contact Us");	
	$smarty->assign('last', $_SESSION["lastviewed"]);
	$smarty->assign('firstname', $_SESSION["firstname"]);
	$smarty->assign('role', $_SESSION["role"]);
	$smarty->assign('top5', $_SESSION["top5"]);	
	$smarty->display('header.tpl');
	
	
	$id = $_SESSION['user_id'];
	$action = $_GET['action'];
	
	//get user info
	$query = "SELECT firstname, lastname, email, role FROM users WHERE user_id = $id";
	
	 /**
	* @desc This include file connects to the database.
	*/
	require 'includes/connect.inc';
	
	
	$result = mysql_query($query, $connection);
	$row = mysql_fetch_array($result);
	
	$fname = $row['firstname'];
	$lname = $row['lastname'];
	$email = $row['email'];
	$role = $row['role'];
	
	mysql_close($connection);
	
	$smarty->assign('id', $id);
	$smarty->assign('fname', $fname);
	$smarty->assign('lname', $lname);
	$smarty->assign('email', $email);
	$smarty->assign('role', $role);
	
	switch($action)
	{
		case 'delete':			
			$smarty->display('deleteprofile.tpl');
			break;
		case 'edit':
			if(isset($_SESSION["errors"]["fname"]))
				$smarty->assign('errorfname', $_SESSION["errors"]["fname"]);
			if(isset($_SESSION["errors"]["lname"]))
				$smarty->assign('errorlname', $_SESSION["errors"]["lname"]);
			if(isset($_SESSION["errors"]["email"]))
				$smarty->assign('erroremail', $_SESSION["errors"]["email"]);
			if(isset($_SESSION["errors"]["pass"]))
				$smarty->assign('errorpass', $_SESSION["errors"]["pass"]);
			$smarty->display('editprofile.tpl');
			break;
	}	
	
	unset($_SESSION['errors']);
	
	//Footer
	$smarty->display('footer.tpl');
	
?>